package com.china.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.china.osourcechina.R;
import com.china.vo.Active;

import java.util.ArrayList;

/**
 * Created by jinyaoguang on 2016/5/10.
 */
public class Friends_Adapter extends BaseAdapter {
    ArrayList<Active> list;
    Context context;
    public Friends_Adapter(ArrayList<Active> list, Context context) {
        this.list=list;
        this.context=context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder h;
        if(convertView==null){
            h=new ViewHolder();
            convertView=View.inflate(context, R.layout.friends_item,null);
            h.iv_friends= (ImageView) convertView.findViewById(R.id.iv_friends);
            h.tv_friends_name= (TextView) convertView.findViewById(R.id.tv_friends_name);
            h.tv_time= (TextView) convertView.findViewById(R.id.tv_friends_time);
            h.tv_objecttitle= (TextView) convertView.findViewById(R.id.tv_friends_objecttitle);
            h.tv_message= (TextView) convertView.findViewById(R.id.tv_friends_message);
            convertView.setTag(h);
        }else{
            h= (ViewHolder) convertView.getTag();
        }
        h.tv_friends_name.setText(list.get(position).getAuthor());
        h.tv_time.setText(list.get(position).getPubDate());
        h.tv_objecttitle.setText(list.get(position).getObjecttitle());
        h.tv_message.setText(list.get(position).getMessage());
        return convertView;
    }

    class ViewHolder{
        ImageView iv_friends;
        TextView tv_friends_name;
        TextView tv_time;
        TextView tv_objecttitle;
        TextView tv_message;
    }
}
